// +---------------------------------------------------------------------------+
// | Copyright (c) 2014-2015.                                                  |
// | Website: http://www.mamahaocai.com/                                       |
// | Author : David 黎 <lovedavid2046@163.com>                                 |
// +---------------------------------------------------------------------------+
/**
 * 发送邮件检查
 */
function get_mobile_code(){
    //var username=document.getElementById('username').value;
    //var reg=/^(13[0-9]|15[0|1|2|3|6|7|8|9]|18[0|2|3|5|6|7|8|9]|17[0])\d{8}$/;
    var username=document.getElementById('username').value;
    var reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var res=username.match(reg);
    if(res){
        $.post("<?php echo U('/code');?>",{username:username},function (msg){
            if(msg=="0"){
                document.getElementById('errorImg').src="__PUBLIC__/images/tick.png";
                messages.innerHTML="邮件发送成功。";
                result.style.display="block";
                $(" #result").fadeOut(5000);
                RemainTime();
            }else if(msg=="1"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="邮件发送失败。";
                result.style.display="block";
            }else if(msg=="2"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="该邮箱已经被注册了。";
                result.style.display="block";
            }else{
                alert(msg);
            }
        });
    }else{
        document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
        messages.innerHTML="请填写正确的邮箱格式。";
        result.style.display="block";
        document.getElementById('username').focus();
    }
}

/**
 * 注册第一步验证
 */
function mstregCheck(){
    //var username=document.getElementById('username').value;
    //var reg=/^(13[0-9]|15[0|1|2|3|6|7|8|9]|18[0|2|3|5|6|7|8|9]|17[0])\d{8}$/;
    var username=document.getElementById('username').value;
    var reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var verify=document.getElementById('verify').value;
    var res=username.match(reg);
    if(res){
        $.post("<?php echo U('/mstregCheck');?>",{username:username,verify:verify},function (msg){
            if(msg=="0"){
                result.style.display="none";
                if(result.style.display=="none"){
                    window.location.href="<?php echo U('/mndreg');?>";
                }else{
                    document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                    messages.innerHTML="错误信息未处理完成。";
                    result.style.display="block";
                }
            }else if(msg=="1"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.png";
                messages.innerHTML="验证码错误。";
                result.style.display="block";
            }else if(msg=="2"){
                messages.innerHTML="该邮箱已经被注册了。";
                result.style.display="block";
            }else if(msg=="3"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="请填写正确的邮箱格式。";
                result.style.display="block";
            }else{
                alert(msg);
            }
        });
    }else{
        document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
        messages.innerHTML="请填写正确的邮箱格式。";
        result.style.display="block";
        document.getElementById('username').focus();
    }
}

var iTime = 59;
var Account;
/**
 * 60秒倒数
 * @constructor
 */
function RemainTime(){
    document.getElementById('zphone').disabled = true;
    var iSecond,sSecond="",sTime="";
    if (iTime >= 0){
        iSecond = parseInt(iTime%60);
        iMinute = parseInt(iTime/60)
        if (iSecond >= 0){
            if(iMinute>0){
                sSecond = iMinute + "分" + iSecond + "秒";
            }else{
                sSecond = iSecond + "秒后重新发送";
            }
        }
        sTime=sSecond;
        if(iTime==0){
            clearTimeout(Account);
            sTime='获取邮箱验证码';
            iTime = 59;
            document.getElementById('zphone').disabled = false;
        }else{
            Account = setTimeout("RemainTime()",1000);
            iTime=iTime-1;
        }
    }else{
        sTime='没有倒计时';
    }
    document.getElementById('zphone').value = sTime;
}
